package com.atguigu.juc.daemon;

import java.util.concurrent.TimeUnit;

/**
 * @Description: 测试 setDaemon()、isDaemon()
 * @author： yeswater
 * @create： 2024/5/28
 */

public class DaemonDemo {
	
	public static void main(String[] args) {
		Thread t1 = new Thread(() -> {
			System.out.println(Thread.currentThread().getName() + "\t开始运行");
			System.out.println(Thread.currentThread().getName() + "\t is daemon\t" + Thread.currentThread().isDaemon());
			while (true){
				
			}
		}, "t1");
		t1.setDaemon(true); // 必须在 start 之前设置 否则会 IllegalThreadStateException
		t1.start();
		
		
		try {
			TimeUnit.SECONDS.sleep(3);
		} catch (InterruptedException e) {
			throw new RuntimeException(e);
		}
		
		System.out.println(Thread.currentThread().getName() + "\t ---- end 主线程");
		
	}
	
}
